import { proxy, useSnapshot } from '@umijs/max';

// 定义状态类型
interface DataState {
  list: any[];
  loading: boolean;
  error: Error | null;
  userInfo:any;
}

// 初始化状态
const dataStore = proxy<DataState>({
  list: [],
  loading: false,
  error: null,
  userInfo:{},
});

const dataActions = {
  setLoading:(loading:boolean) => {
    dataStore.loading = loading;
  },

  setError:(error:Error) => {
    dataStore.error = error;
  },

  setList:(list:any[]) => {
    dataStore.list = list;
  },

  setUserInfo:(userInfo:any) => {
    dataStore.userInfo = userInfo;
  },
}

const useData = () =>(
   {
  ...useSnapshot(dataStore),
  ...dataActions,
}
)

export default  useData;
